package com.lwl.leetcode;

import org.junit.Test;

/**
 * @author lwl
 * @Description TODO
 * @date 2023/8/1 11:04
 */
public class Code43Multiply {
    public String multiply(String num1, String num2) {
        if (num1 == null || num2 == null) {
            return null;
        }
        String res = "0";
        int ten = 0;
        for (int i = num2.length() - 1; i >= 0; i--) {
            String s = multiplyOne(num1, num2.charAt(i), ten++);
            res = add(res, s);
        }
        return res;
    }

    private String multiplyOne(String num1, char num2, int ten) {
        return String.valueOf((Integer.parseInt(num1) * (num2 - '0') * (int) Math.pow(10, ten)));
    }

    private String add(String num1, String num2) {
        return String.valueOf((Integer.parseInt(num1) + Integer.parseInt(num2)));
    }

    @Test
    public void test() {
        System.out.println(multiply("123", "456"));
        System.out.println(multiply("2", "3"));
    }

}
